package com.starlink.utils;

import com.starlink.common.Constants;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author zyh
 */
public class SessionUtil {
    public static <T> T getLoginUser(HttpServletRequest request, Class<T> userType) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            Object attribute = session.getAttribute(Constants.LOGIN_USER);
            if (userType.isInstance(attribute)) {
                return userType.cast(attribute);
            }
        }
        return null;
    }
}
